fix: cv::imencode 添加异常保护,防止触发 save_on_error 时崩溃#19
Open
ocsin1 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cv::imencode 在特定情况下会直接抛出 cv::Exception 而不是返回 false,
导致调用方 imwrite() 无法通过返回值处理错误, 异常穿透到 std::terminate
使进程崩溃。
崩溃定位: opencv_world4_maa!cv::imencodeWithMetadata+0x1017,
说明参数校验已通过, 是 PNG 编码内部的 CV_Assert 失败。
本提交为暂缓措施——try/catch 捕获异常并输出 code/msg/img_type
等诊断信息后返回 false, 防止进程崩溃。cv::imencode 内部失败
的根因尚未确定, 需要通过日志中的错误码进一步排查。
Summary by Sourcery
在
ImageIo::imwrite中为cv::imencode添加异常处理,以防止进程崩溃,并在编码失败时记录诊断信息。Bug 修复:
cv::imencode的未捕获cv::Exception以及其他异常导致的崩溃。功能增强:
cv::imencode因异常失败时,记录详细的错误信息(OpenCV 错误代码、消息、函数、文件、行号以及图像扩展名)。Original summary in English
Summary by Sourcery
Add exception handling around cv::imencode in ImageIo::imwrite to prevent process crashes and log diagnostic information when encoding fails.
Bug Fixes:
Enhancements: